10.5 Direct Assignment of Subscripts

Sometimes, when formulating models, the use of indexes is too complicated for any of the previously mentioned indexing techniques. In those instances, you can, in most cases, use the direct assignment of subscripts. This allows you to give a referred index whatever subscript value you need, instead of having to work from the subsets of the original index. Direct assignments are entered, following the index, with an assignment symbol and an index formula.

To give you an example, when formulating trans-shipment problems, you frequently encounter constraints similar to this one:

    Continuity[k] :

       Prod[k] + SUM(i: Ship[i,j:=k]) = SUM(j: Ship[i:=k,j]) + Sales[k];

In the above example, we want to sum on the left-hand side, how much is shipped to location k, and on the right-hand side, how much is shipped from location k. Since the Ship variable is defined over the indexes i and j, we use direct assignment to assign them the value of k.

Sometimes you need a full-fledged formula to specify the subscripts for the index.

    SUM(i: x[i,j:=last(i)-i+1])

In this example, direct assignment is used to let the subscript j decrease as the subscript i increases.

Assignment of subscripts can also be used to perform multiplication of matrixes and vectors as shown here below:

                INDEX
                    i := 1..3;
                    i2 := i;
                    j := 1..4;

                DATA
                    A[i,j]  := (1, 2, 3, 4,
                                5, 6, 7, 8,
                                9,10,11,12);

                ! Transpose of matrix A
                    B[j,i]  := A[i,j];

                ! Perform matrix multiplication
                    AmultB[i,i2] := SUM(j: A[i,j] * B[j,i:=i2]);

Back To Top | Maximal Home Page | Table of Contents | Previous Page | Next Page